<?php

namespace App\Http\Controllers\V1\Admin;


use App\Models\V1\Information;
use Illuminate\Http\Request;

class InformationController extends BaseController
{

    /**
     * 消息列表-总后台管理    公告分类是给(筹备组)用的
     * @param Request $request
     * @return void
     */
    public function index(Request $request)
    {

        $pageSize = $request->input('pageSize', 10);
        $order = $request->input('order', 'desc');
        $sort = $request->input('sort', 'id');

        $query = Information::query();
        if ($request->filled('title')) {
            $query->where('title', 'like', "%" . $request->input('title') . "%");
        }

        $query->orderBy($sort, $order);
        $data = $query->paginate($pageSize);
        return ajax_output(200, "成功", $data);
    }

    /**
     * 添加消息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(Request $request)
    {

        $notice_model = new Information();
        $notice_model->create([
            'title' => $request->input('title'),
            'content' => $request->input('content'),
            'state' => $request->input('state'),
            'remark' => $request->input('remark'),
        ]);
        return ajax_output(200, "成功");
    }

    /**
     * 修改消息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(Request $request, $id)
    {
        $notice_model = new Information();
        $vo = $notice_model->find($id);
        $vo->update([
            'title' => $request->input('title'),
            'content' => $request->input('content'),
            'state' => $request->input('state'),
            'remark' => $request->input('remark'),
        ]);
        return ajax_output(200, "成功");
    }

    /**
     * 消息详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function show(Request $request, $id)
    {
        $vo = Information::find($id);
        return ajax_output(200, "成功", $vo);
    }


    /**
     * 删除消息
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $id = explode(',',$id);
        Information::destroy($id);
        return ajax_output(200, "成功");
    }
}
